package com.app.brilliant.language.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * @className: MessageSourceUtil
 * @description: 国际化语言工具类
 * @date: Created in 10:24 2023/1/14
 * @author: ZHX
 */

@Component
public class MessageSourceUtil {
    @Autowired
    private MessageSource messageSource;

    public String getMessage(String code, String language,String defaultValue) {
        if ("en".equals(language)){
            return messageSource.getMessage(code, null,defaultValue,  Locale.US);
        } else if("zh".equals(language)){
            return messageSource.getMessage(code, null,defaultValue, Locale.CHINA);
        }else if("zhT".equals(language)){
            return messageSource.getMessage(code, null,defaultValue, Locale.TAIWAN);
        }
        return messageSource.getMessage(code, null,defaultValue, Locale.US);
    }

    public String getMessage(String code, String language) {
        return getMessage(code,language,"");
    }
}
